package easy;

import java.util.Set;

public class Solution_345 {
    public static String reverseVowels(String s) {
        if (s.length()<2) {
            return s;
        }
        char c;
        boolean swap = false;
        char[] chars = s.toCharArray();
        for (int begin = 0, end = chars.length-1;begin<end;) {
            int index = swap?end:begin;
            if (chars[index] == 'a' || chars[index] == 'A'
                || chars[index] == 'e' || chars[index] == 'E'
                || chars[index] == 'i' || chars[index] == 'I'
                || chars[index] == 'o' || chars[index] == 'O'
                || chars[index] == 'u' || chars[index] == 'U') {
                if (swap) {
                    c = chars[begin];
                    chars[begin] = chars[end];
                    chars[end] = c;
                    begin++;
                    end--;
                }
                swap = !swap;
            } else {
                if (swap) {
                    end--;
                } else {
                    begin++;
                }
            }
        }
        return new String(chars);
    }

    public static void main(String[] args) {
        System.out.println(reverseVowels("leetcode"));
    }
}
